<?php
/**
 * Created by PhpStorm.
 * User: stupboy
 * Date: 2018/5/29
 * Time: 14:13
 * Mail:87658989@qq.com
 */

namespace app\open\validate;

use app\base\validate\BaseValidate;

class CarlifeValidate extends BaseValidate
{
    protected $rule = [
        'fields'    => 'checkField',
        'where_json'=> 'checkJson',
        'page'      => 'number',
        'pagenum'   => 'number',
        'counts'    => 'number',

        'id' => 'require|checkIDs',
    ];

    protected $message = [
        'where_json.checkJson'=>'必须为json字符串'
    ];

    protected $default = [
        'page'   =>1,
        'pagenum'=>10,
        'fields' =>'*',
        'counts' =>9999999,
        'delete' => 2
    ];

    public $scene = [
        'report'=>['fields','where_json','page','pagenum'],
        'buyAdd' => [
            'company_id',
            'user_name',
            'car_brand_id',
            'car_series_id',
            'car_model_id',
            'people',
            'money',
            'buyto',
            'whybuy',
            'state',
            'car_id',
        ],
        'buyCheck' => [
            'car_audit_id',
            'company_id',
            'user_name',
            'car_brand_id',
            'car_series_id',
            'car_model_id',
            'people',
            'money',
            'buyto',
            'whybuy',
            'state',
            'car_id',
        ],
        'buyDelete' => [
            'car_audit_id',
        ],
        'scrapAdd' => [
            'car_id',
            'why',
        ],
        'scrapCheck' => [
            'car_scrap_id',
            'state',
            'scrap_add',
            'scrap_check',
            'scrap_image',
        ],
        'scrapDelete' => [
            'car_scrap_id',
        ],
        'sllAdd' => [
            'car_id',
            'why',
        ],
        'sellCheck' => [
            'car_auction_id',
            'state',
            'true_money',
            'want_money',
        ],
        'sellDelete' => [
            'car_auction_id',
        ],
        'car_number_edit' => [
            'delete',
            'car_id',
            'car_number',
        ],
        'transferAdd' => [
            'goto_company_id',
            'car_id',
        ],
        'transferEdit' => [
            'car_transfer_id',
            'provincial_administration_result',
            'bureau_of_finance_result',
            'transfer_document',
            'disposition_of_assets',
        ],
        'transferDelete' => [
            'car_transfer_id',
            'delete',
        ],
    ];

    public function checkField($value){
        if($value=='*') return true;
        return true;
    }

    public function checkJson($value){
        if($value == null) return true;
        if(is_array(json_decode($value,true))) return true;
        return false;
    }
}